func reverse(s [][]int) [][]int {
    for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 {
        s[i], s[j] = s[j], s[i]
    }
    return s
}

func levelOrderBottom(root *TreeNode) [][]int {
    if root == nil{
        return [][]int{}
    }
    queue := []*TreeNode{root}
    ans := [][]int{}
    for len(queue) > 0 {
        tmp := []int{}
        newQueue := []*TreeNode{}
        for _,node := range(queue) {
            tmp = append(tmp, node.Val)
            if node.Left != nil {
                newQueue = append(newQueue, node.Left)
            }
            if node.Right != nil {
                newQueue = append(newQueue, node.Right)
            }
            
        }
        ans = append(ans, tmp)
        // fmt.Println(newQueue)
        queue = newQueue
    }
    return reverse(ans)
}